{% extends "base.html" %}
{% block title %}添加组织架构{% endblock %}
{% block navbar %}{{ super() }}{% endblock %}
{% block styles %}{{ super() }}
<style>
    .main-div {
        background: #ffffff none repeat scroll 0 0;
        border-radius: 2px;
        margin: 10px auto 30px;
        max-width: 80%;
        padding: 20px 20px 20px 20px;
    }

    body {
        padding-top: 100px;
    }
</style>
{% endblock %}
{% block scripts %}{{ super() }}
<script>

    $("#bchoose").click(function () {
        var inputtext = $("#binput").val();
        var users = inputtext.trim().split(/\s+/);

        $('input[type=checkbox]').each(function () {
            var currentname = $(this).data("user-name");
            if (users.includes(currentname)) {
                this.checked = true;
            }
        })
    });
    $("#bunchoose").click(function () {
        $('input[type=checkbox]').each(function () {
            this.checked = false;
        })
    });


</script>
{% endblock %}
{% block content %}
<div class="container">
    <div class="row">
        <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
        <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
            {% include 'flash_message.html' %}
            <h2>
                {{ project_name[0] }} {{ project_name[1] }}
            </h2>
            <div class="alert alert-success">
                可以在下方输入需要添加的用户姓名，用空格分开，可批量选中
            </div>
            <textarea id="binput" cols="90" rows="10"></textarea>
            <button type="button" id="bchoose">选中输入清单</button>
            <button type="button" id="bunchoose">取消选中</button>

            <form action="{{ url_for('bp_assess.add_project_org', project_id=project_id) }}" method="POST">
                <div>
                    {% for user in users %}
                    <input type="checkbox" name="projectuser" data-user-name="{{ user[2] }}" value="{{ user[0] }}">
                    {{ user[1] }} {{ user[2] }}
                    {% endfor %}
                </div>

                <button type="submit" class="btn btn-primary">Submit</button>
            </form>
        </div>
        <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
    </div>
</div>
{% endblock %}